package com.sq.universe.system.entity;

import com.sq.universe.base.entity.BaseEntity;
import org.springframework.util.StringUtils;

/**
 * 代码生成实体类
 */
public class AutoCodeEntity extends BaseEntity {

    /**
     * 字段名称
     */
    private String field;

    /**
     * 字段类型
     */
    private String type;

    /**
     * 字符集合
     */
    private String collation;

    /**
     * 是否为null
     */
    private String Null;

    /**
     * key 类型
     */
    private String key;

    /**
     * 默认值
     */
    private String Default;


    private String extra;

    /**
     * 权限情况
     */
    private String privileges;

    /**
     * 备注
     */
    private String comment;

    /**
     * 列表中显示名称
     */
    private String listName;

    /**
     * 查询方式
     */
    private String queryMethods;

    /**
     * 是否在列表中显示
     */
    private Boolean listShow = true;;

    /**
     * 是否在编辑页显示
     */
    private Boolean editShow = true;;

    /**
     * 是否支持查询
     */
    private Boolean query = true;

    /**
     * 是否简单查询
     */
    private Boolean simpleQuery = false;

    /**
     * 查询地址
     */
    private String selectUrl;

    /**
     * 下拉条件的的KEY
     */
    private String selectKey;

    /**
     * 下拉的value
     */
    private String selectValue;

    /**
     * Java数据类型
     */
    private String javaType;

    /**
     * Java字段名称
     */
    private String javaField;

    public AutoCodeEntity(){

    }


    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
        if(StringUtils.isEmpty(this.listName)){
            this.listName = this.comment;
        }
    }

    public void setType(String type){
        this.type = type;
        if(StringUtils.isEmpty(this.queryMethods)){
            if(type.indexOf("date") > -1){
                this.queryMethods = "between";
            }else if(type.indexOf("varchar") > -1){
                this.queryMethods = "like";
            }else {
                this.queryMethods = "=";
            }
        }
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
        if(field.indexOf("create_user") > -1 ||
                field.indexOf("create_time") > -1 ||
                field.indexOf("update_user") > -1 ||
                field.indexOf("update_time") > -1 ||
                field.indexOf("_del") > -1){
            this.listShow = false;
            this.editShow = false;
            this.query = false;
        }
    }

    public String getType() {
        return type;
    }

    public String getCollation() {
        return collation;
    }

    public void setCollation(String collation) {
        this.collation = collation;
    }

    public String getNull() {
        return Null;
    }

    public void setNull(String aNull) {
        Null = aNull;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getDefault() {
        return Default;
    }

    public void setDefault(String aDefault) {
        Default = aDefault;
    }

    public String getExtra() {
        return extra;
    }

    public void setExtra(String extra) {
        this.extra = extra;
    }

    public String getPrivileges() {
        return privileges;
    }

    public void setPrivileges(String privileges) {
        this.privileges = privileges;
    }

    public String getListName() {
        return listName;
    }

    public void setListName(String listName) {
        if(StringUtils.isEmpty(listName)){
            return ;
        }
        this.listName = listName;
    }

    public String getQueryMethods() {
        return queryMethods;
    }

    public void setQueryMethods(String queryMethods) {
        if(queryMethods == null){
            return;
        }
        this.queryMethods = queryMethods;
    }

    public Boolean getListShow() {
        return listShow;
    }

    public void setListShow(Boolean listShow) {
        if(listShow == null){
            listShow = true;
        }
        this.listShow = listShow;
    }

    public Boolean getEditShow() {
        return editShow;
    }

    public void setEditShow(Boolean editShow) {
        if(editShow == null){
            editShow = true;
        }
        this.editShow = editShow;
    }

    public Boolean getQuery() {
        return query;
    }

    public void setQuery(Boolean query) {
        this.query = query;
    }

    public Boolean getSimpleQuery() {
        return simpleQuery;
    }

    public void setSimpleQuery(Boolean simpleQuery) {
        if(simpleQuery == null){
            simpleQuery = false;
        }
        this.simpleQuery = simpleQuery;
    }

    public String getSelectUrl() {
        return selectUrl;
    }

    public void setSelectUrl(String selectUrl) {
        this.selectUrl = selectUrl;
    }

    public String getSelectKey() {
        return selectKey;
    }

    public void setSelectKey(String selectKey) {
        this.selectKey = selectKey;
    }

    public String getSelectValue() {
        return selectValue;
    }

    public void setSelectValue(String selectValue) {
        this.selectValue = selectValue;
    }

    public String getJavaType() {
        return javaType;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }

    public String getJavaField() {
        return javaField;
    }

    public void setJavaField(String javaField) {
        this.javaField = javaField;
    }
}
